import {
  createRouter,
  createWebHashHistory,
  // LocationQueryRaw,
} from "vue-router";
// import NProgress from 'nprogress'; // progress bar
// import 'nprogress/nprogress.css';

// import usePermission from '@/hooks/permission';
// import { useUserStore } from "@/store";
// import PageLayout from '@/layout/page-layout.vue';
// import { isLogin } from '@/utils/auth';
// import Login from './modules/login';
// import appRoutes from './modules';

// NProgress.configure({ showSpinner: false }); // NProgress Configuration
const Layouts = () => import("@/layout/index.vue");
export const constantRoutes = [
  {
    path: "/",
    redirect: "/login",
  },
  // Login,
  {
    name: "login",
    path: "/login",
    component: () => import("../views/login/index.vue"),
    // children: appRoutes,
  },
  {
    path: "/",
    component: Layouts,
    redirect: "/workspace",
    meta: {
      title: "首页",
      icon: "Location",
      roles: ["user", "admin"],
    },
    children: [
      {
        path: "/workspace",
        component: () => import("@/views/workspace/index.vue"),
        name: "workspace",
        meta: {
          title: "工作台",
          roles: ["user", "admin"],
        },
      },
      {
        path: "/user",
        component: () => import("@/views/user/index.vue"),
        name: "user",
        meta: {
          title: "用户",
          roles: ["admin"],
        },
      },
    ],
  },

  {
    name: "business",
    path: "/business",
    component: () => import("@/views/shopping/business.vue"),
    meta: {
      title: "商家",
      icon: "Location",
      hide: false,
    },
  },
  {
    name: "commodity",
    path: "/commodity",
    component: () => import("@/views/shopping/commodity.vue"),
    meta: {
      title: "商品",
      icon: "Location",
      hide: false,
    },
  },
  {
    // path: '/404',
    path: "/:pathMatch(.*)*", // 防止浏览器刷新时路由未找到警告提示: vue-router.mjs:35 [Vue Router warn]: No match found for location with path "/xxx"
    component: () => import("@/views/error-page/404.vue"),
  },
];
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
});
export default router;
